function mxWindow(title, content, x, y, width, height, minimizable, movable, replaceNode, style)
{
	if (content != null)
	{
		minimizable = (minimizable != null) ? minimizable : true;
		this.content = content;
		this.init(x, y, width, height, style);
		this.installMaximizeHandler();
		this.installMinimizeHandler();
		this.installCloseHandler();
		this.setMinimizable(minimizable);
		mxUtils.write(this.title, title || '');

		if (movable == null || movable)
		{
			this.installMoveHandler();
		}

		if (replaceNode != null && replaceNode.parentNode != null)
		{
			replaceNode.parentNode.replaceChild(this.div, replaceNode);
		}
		else
		{
			document.body.appendChild(this.div);
		}
	}
};
mxWindow.prototype = new mxEventSource();
mxWindow.prototype.constructor = mxWindow;
mxWindow.prototype.closeImage = mxClient.imageBasePath + 'close.gif';
mxWindow.prototype.minimizeImage = mxClient.imageBasePath + 'minimize.gif';
mxWindow.prototype.normalizeImage = mxClient.imageBasePath + 'normalize.gif';
mxWindow.prototype.maximizeImage = mxClient.imageBasePath + 'maximize.gif';
mxWindow.prototype.resizeImage = mxClient.imageBasePath + 'resize.gif';
mxWindow.prototype.visible = false;
mxWindow.prototype.content = false;
mxWindow.prototype.minimumSize = new mxRectangle(0, 0, 50, 40);
mxWindow.prototype.content = false;
mxWindow.prototype.destroyOnClose = true;
mxWindow.prototype.init = function(x, y, width, height, style)
{
	style = (style != null) ? style : 'mxWindow';
	this.div = document.createElement('div');
	this.div.className = style;
	this.div.style.left = x + 'px';
	this.div.style.top = y + 'px';

	if (!mxClient.IS_IE && mxClient.WINDOW_SHADOWS)
	{
		this.shadow = document.createElement('div');
		this.shadow.style.background = mxConstants.SVG_SHADOWCOLOR;
		mxUtils.setOpacity(this.shadow, 70);
		this.shadow.style.position = 'absolute';
		this.shadow.style.display = 'inline';
	}
	else if (mxClient.IS_IE && !mxClient.WINDOW_SHADOWS)
	{
		this.div.style.filter = '';
	}
	this.table = document.createElement('table');
	this.table.className = style;

	if (width != null)
	{
		if (!mxClient.IS_IE)
		{
			this.div.style.width = width + 'px';
		}
		this.table.style.width = width + 'px';
	}

	if (height != null)
	{
		if (!mxClient.IS_IE)
		{
			this.div.style.height = height + 'px';
		}
		this.table.style.height = height + 'px';
	}
	var tbody = document.createElement('tbody');
	var tr = document.createElement('tr');
	this.title = document.createElement('td');
	this.title.className = style + 'Title';
	tr.appendChild(this.title);
	tbody.appendChild(tr);
	tr = document.createElement('tr');
	this.td = document.createElement('td');
	this.td.className = style + 'Pane';
	this.contentWrapper = document.createElement('div');
	this.contentWrapper.className = style + 'Pane';
	this.contentWrapper.style.width = '100%';
	this.contentWrapper.appendChild(this.content);

	if (mxClient.IS_IE || this.content.nodeName.toUpperCase() != 'DIV')
	{
		this.contentWrapper.style.height = '100%';
	}
	this.td.appendChild(this.contentWrapper);
	tr.appendChild(this.td);
	tbody.appendChild(tr);
	this.table.appendChild(tbody);
	this.div.appendChild(this.table);
	var self = this;
	var activator = function(evt)
	{
		self.activate();
	};
	mxEvent.addListener(this.title, 'mousedown', activator);
	mxEvent.addListener(this.table, 'mousedown', activator);

	if (this.shadow != null)
	{
		mxEvent.addListener(this.div, 'DOMNodeInserted', function(evt)
		{
			var node = mxEvent.getSource(evt);
			var loadHandler = function(evt)
			{
				mxEvent.removeListener(node, 'load', loadHandler);
				self.updateShadow();
			};
			mxEvent.addListener(node, 'load', loadHandler);
			self.updateShadow();
		});
	}
	this.hide();
};
mxWindow.prototype.setScrollable = function(scrollable)
{
	if (scrollable)
	{
		this.contentWrapper.style.overflow = 'auto'
	}
	else
	{
		this.contentWrapper.style.overflow = 'hidden'
	}
};
mxWindow.prototype.updateShadow = function()
{
	if (this.shadow != null)
	{
		this.shadow.style.display = this.div.style.display;
		this.shadow.style.left = (parseInt(this.div.style.left) + 3) + 'px';
		this.shadow.style.top = (parseInt(this.div.style.top) + 3) + 'px';
		this.shadow.style.width = this.div.offsetWidth + 'px';
		this.shadow.style.height = this.div.offsetHeight + 'px';

		if (this.shadow.parentNode != this.div.parentNode)
		{
			this.div.parentNode.appendChild(this.shadow);
		}
	}
};
mxWindow.prototype.activate = function()
{
	if (mxWindow.activeWindow != this)
	{
		var style = mxUtils.getCurrentStyle(this.getElement());
		var index = (style != null) ? style.zIndex : 3;

		if (mxWindow.activeWindow)
		{
			var elt = mxWindow.activeWindow.getElement();

			if (elt != null && elt.style != null)
			{
				elt.style.zIndex = index;
			}
		}
		var oldWindow = mxWindow.activeWindow;
		this.getElement().style.zIndex = index + 1;
		mxWindow.activeWindow = this;
		this.fireEvent(mxEvent.ACTIVATE, new mxEventObject([oldWindow]));
	}
};
mxWindow.prototype.getElement = function()
{
	return this.div;
};
mxWindow.prototype.fit = function()
{
	mxUtils.fit(this.div);
};
mxWindow.prototype.isResizable = function()
{
	if (this.resize != null)
	{
		return this.resize.style.display != 'none';
	}
	return false;
};
mxWindow.prototype.setResizable = function(resizable)
{
	if (resizable)
	{
		if (this.resize == null)
		{
			this.resize = document.createElement('img');
			this.resize.style.position = 'absolute';
			this.resize.style.bottom = '2px';
			this.resize.style.right = '2px';
			this.resize.setAttribute('src', mxClient.imageBasePath + 'resize.gif');
			this.resize.style.cursor = 'nw-resize';
			var self = this;
			mxEvent.addListener(this.resize, 'mousedown', function(evt)
			{
				self.activate();
				var startX = evt.clientX;
				var startY = evt.clientY;
				var width = self.div.offsetWidth;
				var height = self.div.offsetHeight;

				var dragHandler = function(evt)
				{
					var dx = evt.clientX - startX;
					var dy = evt.clientY - startY;
					self.setSize(width + dx, height + dy);
					self.updateShadow();
					self.fireEvent(mxEvent.RESIZE, evt);
					mxEvent.consume(evt);
				};
				var dropHandler = function(evt)
				{
					mxEvent.removeListener(document, 'mousemove', dragHandler);
					mxEvent.removeListener(document, 'mouseup', dropHandler);
					self.fireEvent(mxEvent.RESIZE_END, evt);
					mxEvent.consume(evt);
				};
				mxEvent.addListener(document, 'mousemove', dragHandler);
				mxEvent.addListener(document, 'mouseup', dropHandler);
				self.fireEvent(mxEvent.RESIZE_START, evt);
				mxEvent.consume(evt);
			});
			this.div.appendChild(this.resize);
		}
		else
		{
			this.resize.style.display = 'inline';
		}
	}
	else if (this.resize != null)
	{
		this.resize.style.display = 'none';
	}
};
mxWindow.prototype.setSize = function(width, height)
{
	width = Math.max(this.minimumSize.width, width);
	height = Math.max(this.minimumSize.height, height);

	if (!mxClient.IS_IE)
	{
		this.div.style.width = width + 'px';
		this.div.style.height = height + 'px';
	}
	this.table.style.width = width + 'px';
	this.table.style.height = height + 'px';

	if (!mxClient.IS_IE)
	{
		this.contentWrapper.style.height = (this.div.offsetHeight - this.title.offsetHeight - 2) + 'px';
	}
};
mxWindow.prototype.setMinimizable = function(minimizable)
{
	this.minimize.style.display = (minimizable) ? '' : 'none';
};
mxWindow.prototype.installMinimizeHandler = function()
{
	this.minimize = document.createElement('img');
	this.minimize.setAttribute('src', this.minimizeImage);
	this.minimize.setAttribute('align', 'right');
	this.minimize.setAttribute('title', 'Minimize');
	this.minimize.style.cursor = 'pointer';
	this.minimize.style.marginRight = '1px';
	this.minimize.style.display = 'none';
	this.title.appendChild(this.minimize);
	var minimized = false;
	var maxDisplay = null;
	var height = null;
	var self = this;
	var funct = function(evt)
	{
		self.activate();

		if (!minimized)
		{
			minimized = true;
			self.minimize.setAttribute('src', self.normalizeImage);
			self.minimize.setAttribute('title', 'Normalize');
			self.contentWrapper.style.display = 'none';
			maxDisplay = self.maximize.style.display;
			self.maximize.style.display = 'none';
			height = self.table.style.height;

			if (!mxClient.IS_IE)
			{
				self.div.style.height = self.title.offsetHeight + 'px';
			}
			self.table.style.height = self.title.offsetHeight + 'px';

			if (self.resize != null)
			{
				self.resize.style.visibility = 'hidden';
			}
			self.updateShadow();
			self.fireEvent(mxEvent.MINIMIZE, evt);
		}
		else
		{
			minimized = false;
			self.minimize.setAttribute('src', self.minimizeImage);
			self.minimize.setAttribute('title', 'Minimize');
			self.contentWrapper.style.display = '';
			self.maximize.style.display = maxDisplay;

			if (!mxClient.IS_IE)
			{
				self.div.style.height = height;
			}
			self.table.style.height = height;

			if (self.resize != null)
			{
				self.resize.style.visibility = 'visible';
			}
			self.updateShadow();
			self.fireEvent(mxEvent.NORMALIZE, evt);
		}
		mxEvent.consume(evt);
	};
	mxEvent.addListener(self.minimize, 'mousedown', funct);
};
mxWindow.prototype.setMaximizable = function(maximizable)
{
	this.maximize.style.display = (maximizable) ? '' : 'none';
};
mxWindow.prototype.installMaximizeHandler = function()
{
	this.maximize = document.createElement('img');
	this.maximize.setAttribute('src', this.maximizeImage);
	this.maximize.setAttribute('align', 'right');
	this.maximize.setAttribute('title', 'Maximize');
	this.maximize.style.cursor = 'default';
	this.maximize.style.marginLeft = '1px';
	this.maximize.style.cursor = 'pointer';
	this.maximize.style.display = 'none';
	this.title.appendChild(this.maximize);
	var maximized = false;
	var x = null;
	var y = null;
	var height = null;
	var width = null;
	var self = this;
	var funct = function(evt)
	{
		self.activate();

		if (self.maximize.style.display != 'none')
		{
			if (!maximized)
			{
				maximized = true;
				self.maximize.setAttribute('src', self.normalizeImage);
				self.maximize.setAttribute('title', 'Normalize');
				self.contentWrapper.style.display = '';
				self.minimize.style.visibility = 'hidden';
				x = parseInt(self.div.style.left);
				y = parseInt(self.div.style.top);
				height = self.table.style.height;
				width = self.table.style.width;
				self.div.style.left = '0px';
				self.div.style.top = '0px';

				if (!mxClient.IS_IE)
				{
					self.div.style.height = (document.body.clientHeight - 2) + 'px';
					self.div.style.width = (document.body.clientWidth - 2) + 'px';
				}
				self.table.style.width = (document.body.clientWidth - 2) + 'px';
				self.table.style.height = (document.body.clientHeight - 2) + 'px';

				if (self.resize != null)
				{
					self.resize.style.visibility = 'hidden';
				}

				if (self.shadow != null)
				{
					self.shadow.style.display = 'none';
				}

				if (!mxClient.IS_IE)
				{
					var style = mxUtils.getCurrentStyle(self.contentWrapper);

					if (style.overflow == 'auto' || self.resize != null)
					{
						self.contentWrapper.style.height = (self.div.offsetHeight - self.title.offsetHeight - 2) + 'px';
					}
				}
				self.fireEvent(mxEvent.MAXIMIZE, evt);
			}
			else
			{
				maximized = false;
				self.maximize.setAttribute('src', self.maximizeImage);
				self.maximize.setAttribute('title', 'Maximize');
				self.contentWrapper.style.display = '';
				self.minimize.style.visibility = '';
				self.div.style.left = x + 'px';
				self.div.style.top = y + 'px';

				if (!mxClient.IS_IE)
				{
					self.div.style.height = height;
					self.div.style.width = width;
					var style = mxUtils.getCurrentStyle(self.contentWrapper);

					if (style.overflow == 'auto' || self.resize != null)
					{
						self.contentWrapper.style.height = (self.div.offsetHeight - self.title.offsetHeight - 2) + 'px';
					}
				}
				self.table.style.height = height;
				self.table.style.width = width;

				if (self.resize != null)
				{
					self.resize.style.visibility = 'visible';
				}
				self.updateShadow();
				self.fireEvent(mxEvent.NORMALIZE, evt);
			}
			mxEvent.consume(evt);
		}
	};
	mxEvent.addListener(this.maximize, 'mousedown', funct);
	mxEvent.addListener(this.title, 'dblclick', funct);
};
mxWindow.prototype.installMoveHandler = function()
{
	this.title.style.cursor = 'move';
	var self = this;
	mxEvent.addListener(this.title, 'mousedown', function(evt)
	{
		var startX = evt.clientX;
		var startY = evt.clientY;
		var x = self.getX();
		var y = self.getY();

		var dragHandler = function(evt)
		{
			var dx = evt.clientX - startX;
			var dy = evt.clientY - startY;
			self.setLocation(x + dx, y + dy);
			self.fireEvent(mxEvent.MOVE, evt);
			mxEvent.consume(evt);
		};
		var dropHandler = function(evt)
		{
			mxEvent.removeListener(document, 'mousemove', dragHandler);
			mxEvent.removeListener(document, 'mouseup', dropHandler);
			self.fireEvent(mxEvent.MOVE_END, evt);
			mxEvent.consume(evt);
		};
		mxEvent.addListener(document, 'mousemove', dragHandler);
		mxEvent.addListener(document, 'mouseup', dropHandler);
		self.fireEvent(mxEvent.MOVE_START, evt);
		mxEvent.consume(evt);
	});
};
mxWindow.prototype.setLocation = function(x, y)
{
	this.div.style.left = x + 'px';
	this.div.style.top = y + 'px';
	this.updateShadow();
};
mxWindow.prototype.getX = function()
{
	return parseInt(this.div.style.left);
};
mxWindow.prototype.getY = function()
{
	return parseInt(this.div.style.top);
};
mxWindow.prototype.installCloseHandler = function()
{
	this.closeImg = document.createElement('img');
	this.closeImg.setAttribute('src', this.closeImage);
	this.closeImg.setAttribute('align', 'right');
	this.closeImg.setAttribute('title', 'Close');
	this.closeImg.style.marginLeft = '2px';
	this.closeImg.style.cursor = 'pointer';
	this.closeImg.style.display = 'none';
	this.title.insertBefore(this.closeImg, this.title.firstChild);
	var self = this;
	mxEvent.addListener(this.closeImg, 'mousedown', function(evt)
	{
		self.fireEvent(mxEvent.CLOSE, evt);

		if (self.destroyOnClose)
		{
			self.destroy();
		}
		else
		{
			self.setVisible(false);
		}
		mxEvent.consume(evt);
	});
};
mxWindow.prototype.setImage = function(image)
{
	this.image = document.createElement('img');
	this.image.setAttribute('src', image);
	this.image.setAttribute('align', 'left');
	this.image.style.marginRight = '4px';
	this.image.style.marginLeft = '0px';
	this.image.style.marginTop = '-2px';
	this.title.insertBefore(this.image, this.title.firstChild);
};
mxWindow.prototype.setClosable = function(closable)
{
	this.closeImg.style.display = (closable) ? '' : 'none';
};
mxWindow.prototype.isVisible = function()
{
	if (this.div != null)
	{
		return this.div.style.display != 'none';
	}
	return false;
};
mxWindow.prototype.setVisible = function(visible)
{
	if (this.div != null && this.isVisible() != visible)
	{
		if (visible)
		{
			this.show();
		}
		else
		{
			this.hide();
		}
	}
	this.updateShadow();
};
mxWindow.prototype.show = function()
{
	this.div.style.display = '';
	this.activate();
	var style = mxUtils.getCurrentStyle(this.contentWrapper);

	if (!mxClient.IS_IE && (style.overflow == 'auto' || this.resize != null))
	{
		this.contentWrapper.style.height = (this.div.offsetHeight - this.title.offsetHeight - 2) + 'px';
	}
	this.fireEvent(mxEvent.SHOW);
};
mxWindow.prototype.hide = function()
{
	this.div.style.display = 'none';
	this.fireEvent(mxEvent.HIDE);
};
mxWindow.prototype.destroy = function()
{
	this.fireEvent(mxEvent.DESTROY);

	if (this.div != null)
	{
		mxEvent.release(this.div);
		this.div.parentNode.removeChild(this.div);
		this.div = null;
	}

	if (this.shadow != null)
	{
		this.shadow.parentNode.removeChild(this.shadow);
		this.shadow = null;
	}
	this.title = null;
	this.content = null;
	this.contentWrapper = null;
};

function mxForm(className)
{
	this.table = document.createElement('table');
	this.table.className = className;
	this.body = document.createElement('tbody');
	this.table.appendChild(this.body);
};
mxForm.prototype.table = null;
mxForm.prototype.body = false;
mxForm.prototype.getTable = function()
{
	return this.table;
};
mxForm.prototype.addButtons = function(okFunct, cancelFunct)
{
	var tr = document.createElement('tr');
	var td = document.createElement('td');
	tr.appendChild(td);
	td = document.createElement('td');
	var button = document.createElement('button');
	mxUtils.write(button, mxResources.get('ok') || 'OK');
	td.appendChild(button);
	var self = this;
	mxEvent.addListener(button, 'click', function()
	{
		okFunct();
	});
	button = document.createElement('button');
	mxUtils.write(button, mxResources.get('cancel') || 'Cancel');
	td.appendChild(button);
	mxEvent.addListener(button, 'click', function()
	{
		cancelFunct();
	});
	tr.appendChild(td);
	this.body.appendChild(tr);
};
mxForm.prototype.addText = function(name, value)
{
	var input = document.createElement('input');
	input.setAttribute('type', 'text');
	input.value = value;
	return this.addField(name, input);
};
mxForm.prototype.addCheckbox = function(name, value)
{
	var input = document.createElement('input');
	input.setAttribute('type', 'checkbox');
	this.addField(name, input);

	if (value)
	{
		input.checked = true;
	}
	return input;
};
mxForm.prototype.addTextarea = function(name, value, rows)
{
	var input = document.createElement('textarea');

	if (mxClient.IS_SVG)
	{
		rows--;
	}
	input.setAttribute('rows', rows || 2);
	input.value = value;
	return this.addField(name, input);
};
mxForm.prototype.addCombo = function(name, isMultiSelect, size)
{
	var select = document.createElement('select');

	if (size != null)
	{
		select.setAttribute('size', size);
	}

	if (isMultiSelect)
	{
		select.setAttribute('multiple', 'true');
	}
	return this.addField(name, select);
};
mxForm.prototype.addOption = function(combo, label, value, isSelected)
{
	var option = document.createElement('option');
	mxUtils.writeln(option, label);
	option.setAttribute('value', value);

	if (isSelected)
	{
		option.setAttribute('selected', isSelected);
	}
	combo.appendChild(option);
};
mxForm.prototype.addField = function(name, input)
{
	var tr = document.createElement('tr');
	var td = document.createElement('td');
	mxUtils.write(td, name);
	tr.appendChild(td);
	td = document.createElement('td');
	td.appendChild(input);
	tr.appendChild(td);
	this.body.appendChild(tr);
	return input;
};

function mxImage(src, width, height)
{
	this.src = src;
	this.width = width;
	this.height = height;
};
mxImage.prototype.src = null;
mxImage.prototype.width = null;
mxImage.prototype.height = null;

function mxDivResizer(div, container)
{
	if (div.nodeName.toLowerCase() == 'div')
	{
		if (container == null)
		{
			container = window;
		}
		this.div = div;
		var style = mxUtils.getCurrentStyle(div);

		if (style != null)
		{
			this.resizeWidth = style.width == 'auto';
			this.resizeHeight = style.height == 'auto';
		}
		var self = this;
		mxEvent.addListener(container, 'resize', function(evt)
		{
			if (!self.handlingResize)
			{
				self.handlingResize = true;
				self.resize();
				self.handlingResize = false;
			}
		});
		this.resize();
	}
};
mxDivResizer.prototype.resizeWidth = true;
mxDivResizer.prototype.resizeHeight = true;
mxDivResizer.prototype.handlingResize = false;
mxDivResizer.prototype.resize = function()
{
	var w = this.getDocumentWidth();
	var h = this.getDocumentHeight();
	var l = parseInt(this.div.style.left);
	var r = parseInt(this.div.style.right);
	var t = parseInt(this.div.style.top);
	var b = parseInt(this.div.style.bottom);

	if (this.resizeWidth && !isNaN(l) && !isNaN(r) && l >= 0 && r >= 0 && w - r - l > 0)
	{
		this.div.style.width = (w - r - l) + 'px';
	}

	if (this.resizeHeight && !isNaN(t) && !isNaN(b) && t >= 0 && b >= 0 && h - t - b > 0)
	{
		this.div.style.height = (h - t - b) + 'px';
	}
};
mxDivResizer.prototype.getDocumentWidth = function()
{
	return document.body.clientWidth;
};
mxDivResizer.prototype.getDocumentHeight = function()
{
	return document.body.clientHeight;
};